﻿#include "FITKAcousticsVTKGraphObjectSEAShellsBase.h"
#include "FITKAcousticsVTKGraphActor.h"

// VTK
#include <vtkProperty.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkCompositeDataGeometryFilter.h>
#include <vtkExtractBlock.h>

// Data
#include "FITK_Component/FITKAcousticsModel/FITKAbstractSEASubSys.h"

// Graph and filter
#include "FITKAcousticsVTKCommons.h"
#include "FITKAcousticsVTKSharedDataManager.h"
#include "FITKAcousticsVTKGraphObjectSEASelectMergedData.h"
#include "FITK_Interface/FITKVTKAlgorithm/FITKGraphActor.h"

namespace Exchange
{
    FITKAcousticsVTKGraphObjectSEAShellsBase::FITKAcousticsVTKGraphObjectSEAShellsBase(Acoustics::FITKAcousticsSEAModel* seaModel)
        : FITKAcousticsVTKGraphObjectSEASubSystems(seaModel)
    {
        if (!seaModel)
        {
            return;
        }

        // Intiailize the polygon offset.
        m_polygonOffset = FITKAcousticsVTKCommons::s_polygonOffsetSEAShell;

        // Save the data type.
        m_graphInfo.Type = FITKAcousticsVTKCommons::ShellGraph;
    }

    void FITKAcousticsVTKGraphObjectSEAShellsBase::setPickMode(FITKAcousticsVTKCommons::ShapePickMode mode)
    {
        if (!m_fActor)
        {
            return;
        }

        bool pickable = false;

        switch (mode)
        {
        case Exchange::FITKAcousticsVTKCommons::PickAll:
            pickable = true;
            break;
        case Exchange::FITKAcousticsVTKCommons::PickNone:
        case Exchange::FITKAcousticsVTKCommons::PickVertex:
        case Exchange::FITKAcousticsVTKCommons::PickEdge:
        case Exchange::FITKAcousticsVTKCommons::PickFace:
        case Exchange::FITKAcousticsVTKCommons::PickSolid:
        case Exchange::FITKAcousticsVTKCommons::PickNode:
        case Exchange::FITKAcousticsVTKCommons::PickElement:
        default:
            pickable = false;
            break;
        }

        // Update all actors.
        m_fActor->SetPickable(pickable);
    }

    bool FITKAcousticsVTKGraphObjectSEAShellsBase::getDataVisibility()
    {
        // Get the runtime settings for visibility.
        bool showShell = getRuntimeSettingAs<bool>(RTS_KEY_VISIBLE_SEA_SUBSYS_SHELLS, true);
        return this->Superclass::getDataVisibility() && showShell;
    }

    void FITKAcousticsVTKGraphObjectSEAShellsBase::generateGraph()
    {
        // Create actor.
        this->Superclass::generateGraph();

        m_fActor->setActorType(ActorType::SurfaceActor);

        // Enable back face culling.( Each shell's dataset has a set of reversed cells for the 
        // back faces of the shell.)
        m_fActor->GetProperty()->SetBackfaceCulling(true);
    }
}   // namespace Exchange